package com.qf.web.controller;

import com.alibaba.druid.util.StringUtils;
import com.qf.dao.StuDao;
import com.qf.dao.impl.StuDaoImpl;
import com.qf.pojo.Stu;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * projectName:lichengyu
 * author:lcy
 * time:2024/4/30 9:32
 * description:
 */
@WebServlet("/stuservlet")
public class StuServlet extends BaseServlet {
    public String login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String stuname = request.getParameter("stuname");
        String pwd = request.getParameter("pwd");
        System.out.println("pwd");
        if (StringUtils.isEmpty(stuname)) {
            request.setAttribute("msg", "用户名不能为空");
            return "login.jsp";
        }
        if (StringUtils.isEmpty(pwd)) {
            request.setAttribute("msg", "密码不能为空");
            return "login.jsp";
        }
        try {
            StuDao stuService = new StuDaoImpl();
            Stu stu = stuService.login(stuname, pwd);
            request.getSession().setAttribute("stu", stu);
            if(stu.getStatus()==1){
                return"admin.jsp";
            }else {
                return "putong.jsp";
            }
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("msg", "用户登录失败" + e.getMessage());
            return "message.jsp";
        }
    }
}


